//---------------------------------------------------------------------------------
// Copyright (c) 2011, Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------------

namespace Microsoft.Samples.ServiceBus.WindowsPhoneChat.Models
{
    using System;
    using System.Windows.Threading;
    using Microsoft.Samples.AccessControl;

    /// <summary>
    /// Encapsulates various state and contextual information for the current
    /// application session including the Username and Token Provider.
    /// </summary>
    public class ApplicationContext
    {
        private readonly Dispatcher uiDispatcher;

        public ApplicationContext(Dispatcher uiDispatcher)
        {
            if (uiDispatcher == null)
            {
                throw new ArgumentNullException("uiDispatcher");
            }

            this.uiDispatcher = uiDispatcher;

            // TODO: Enter your Service Namespace information here
            // this.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
            //     serviceNamespace: "your namespace name",
            //     issuerName: "owner",
            //     issuerSecret: "your base 64 secret key");
        }

        public TokenProvider TokenProvider { get; private set; }

        public string UserName { get; private set; }

        public Dispatcher UIDispatcher
        {
            get { return this.uiDispatcher; }
        }

        /// <summary>
        /// Completes the authentication process by initializing the Application 
        /// Context.
        /// </summary>
        public void CompleteAuthentication(string userName)
        {
            // Set the username and current token for the session
            this.UserName = userName;
        }
    }
}
